致勝優勢INFO
聯系我們CONTACT

公司地址:茂名市人民南路新村大院22號101

電話:13592986386

網頁微信授權開發您當前的位置:首頁 > 網頁微信授權開發

網頁微信授權開發

發布時間:2018/5/15 15:11:31






Bin 引用DLL

AppCode引用類文件




 protected void Page_Load(object sender, System.EventArgs e)
    {
        if (!IsPostBack)
        {
            string userAgent = Request.UserAgent;
            if (userAgent.ToLower().Contains("micromessenger"))
            {
                //Response.Write("歡迎您在微信中訪問我。"); 
                //code=CODE&state=STATE
                if (Request.QueryString["code"] != null)
                {
                    //第一步:定義APPID等
                    string APPID = "*************************";
                    string APPSECRET = "*************************"; ;

                    //第二步:通過code換取網頁授權access_token
                    string code = Request.QueryString["code"];

                    ZSJson myjson = new ZSJson();
                    string url = "                     string strReturn = myjson.GetFunction(url);
                    JObject jo = JObject.Parse(strReturn);
                    string ACCESS_TOKEN = jo["access_token"].ToString();    //讀取獲取到的ACCESS_TOKEN
                    string OPENID = jo["openid"].ToString();                //讀取獲取到的OPENID
                    Session["openid"] = OPENID;

                    //第四步:拉取用戶信息(需scope為 snsapi_userinfo)
                    string nexturl = "
                    string nextstrReturn = myjson.GetFunction(nexturl);
                    //Response.Write(nextstrReturn);
                    JObject result = JObject.Parse(nextstrReturn);
                    string nickname = result["nickname"].ToString();
                    string sex = result["sex"].ToString();
                    string headimgurl = result["headimgurl"].ToString();
                    string province = result["province"].ToString();
                    string city = result["city"].ToString();


                    /************業務邏輯(默認注冊帳號,注冊完成后進入某個指定頁面)****************************/
                    string Password = "123456";                           //密碼
                    string cMD5Pass = FormsAuthentication.HashPasswordForStoringInConfigFile(Password, "MD5");  //MD5加密
                    SqlConn mysql = new SqlConn();
                    Hashtable httParam = new Hashtable();
                    httParam.Add("@OPType", 777);
                    httParam.Add("@iRole", 1);
                    httParam.Add("@OPENID", OPENID);
                    httParam.Add("@cUserName", nickname);
                    httParam.Add("@cMobile", "");
                    httParam.Add("@cPic", headimgurl);
                    httParam.Add("@cPassword", cMD5Pass);
                    string StoredtName = "tb_User_Proc";
                    DataTable dt = mysql.ExecuteDataTable(StoredtName, httParam, CommandType.StoredProcedure);
                    if (dt.Rows.Count > 0)
                    {
                        CookieManage mycookies = new CookieManage();
                        mycookies.DeleteCookie("UserID");
                        mycookies.DeleteCookie("UserName");
                        mycookies.DeleteCookie("UserMobile");

                        int cookiestime = 1440;
                        mycookies.WriteCookie("UserID", dt.Rows[0]["ID"].ToString(), cookiestime, true);
                        mycookies.WriteCookie("UserName", dt.Rows[0]["cUserName"].ToString(), cookiestime, true);
                        mycookies.WriteCookie("UserMobile", dt.Rows[0]["cMobile"].ToString(), cookiestime, true);

                        Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script language=javascript>autoPage()</script>");
                    }
                    /*************************************/
                }
                else
                {
                    //第一步:用戶同意授權,獲取code
                    //在確保微信公眾賬號擁有授權作用域(scope參數)的權限的前提下(服務號獲得高級接口后,默認擁有scope參數中的snsapi_base和snsapi_userinfo),引導關注者打開如下頁面:
                    string APPID = "*************************";
                    string webdomain = "http://" + HttpContext.Current.Request.Url.Host;
                    string REDIRECT_URI = webdomain + "/Default.aspx";
                    string url = "
                    Response.Redirect(url);
                }
            }
            else
            {
                //非微信瀏覽器打開(電腦,手機瀏覽器)
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script language=javascript>autoPage()</script>");
            }
        }
    }

国产免费午夜福利片在线h|亚洲ⅤA制服丝袜一区二区|国产丝袜在线精品丝袜不卡|免费黄片亚洲高清无码